package com.yt.calendar.controller;


import com.yt.calendar.constant.CalendarConstant;
import com.yt.calendar.entity.Config;
import com.yt.calendar.service.IConfigService;
import com.yt.calendar.vo.ResponseVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 系统配置表 前端控制器
 * </p>
 *
 * @author yt
 * @since 2021-07-16
 */
@RestController
@RequestMapping("/calendar/config")
public class ConfigController {
    @Resource
    private IConfigService iConfigService;

    /**
     * 查询间隔
     */
    @GetMapping("/getInterval")
    public ResponseVo getInterval() {
        Config config = iConfigService.getOneByAppAndTypeAndCodeAndParent(CalendarConstant.APP_ID, CalendarConstant.SCT_DEFAULT, CalendarConstant.SCC_INTERVAL, CalendarConstant.PARENT_ID_TOP);
        return new ResponseVo(1, config == null ? "" : config.getValue());
    }

    /**
     * 修改间隔
     */
    @PostMapping("/saveInterval")
    public ResponseVo saveInterval(@RequestParam("value") String value) {
        if (!value.contains("[") || !value.contains("]")) {
            value = "[" + value + "]";
        }
        iConfigService.updateOneByAppAndTypeAndCodeAndParent(CalendarConstant.APP_ID, CalendarConstant.SCT_DEFAULT, CalendarConstant.SCC_INTERVAL, CalendarConstant.PARENT_ID_TOP, value);
        return new ResponseVo(1);
    }
}

